When payloads get truncated in the DB due to encoding issues, at least do not blow up on reading them

Andrew Cantino 8 years ago
parent
commit
797e7e3b3c
1 changed files with 3 additions and 0 deletions
  1. 3 0
      lib/json_with_indifferent_access.rb

+ 3 - 0
lib/json_with_indifferent_access.rb

@@ -1,6 +1,9 @@
1 1
 class JSONWithIndifferentAccess
2 2
   def self.load(json)
3 3
     ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(json || '{}'))
4
+  rescue JSON::ParserError
5
+    Rails.logger.error "Unparsable JSON in JSONWithIndifferentAccess: #{json}"
6
+    { 'error' => 'unparsable json detected during de-serialization' }
4 7
   end
5 8
 
6 9
   def self.dump(hash)